# zj802_rule.py
import sys
from pathlib import Path

# 获取 template 目录的绝对路径（根据实际结构调整）
current_file = Path(__file__)
template_dir = current_file.parent.parent  # 上两级目录

sys.path.append(str(template_dir))

# 现在可以正常导入
from utils import date_offset_handler, generate_random_data_with_params
from base_rule import BaseRule
from DataProcessor import DataProcessor
import random
import pandas as pd

class ZJ802_Rule(BaseRule):
    def __init__(self, project_info):
        # ✅ 使用 lambda 包装 project_info
        super().__init__("ZJ802", project_info)

        # ✅ 统一通过 get_project_info_func() 获取上下文
        context = project_info

        # 添加字段
        self.add_field("桩号、部位", lambda _: context['施工部位'])
        self.add_field("施工日期", date_offset_handler(0), data_type="date", format="%Y年%m月%d日")
        self.add_field("检验日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")
        self.add_field("质检负责人日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")
        self.add_field("自检员日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")

    def process(self, **kwargs):
        """
        封装处理逻辑，直接返回结果
        :param data_file_path: 数据文件路径（Excel/CSV）
        :return: 处理后的 DataFrame
        """
        data_file_path = current_file.parent / '模板数据.xlsx'
        df = pd.read_excel(data_file_path)
        rules = self.get_rules()

        # ✅ 使用 get_project_info_func()
        processor = DataProcessor(base_data=df, project_info=project_info, rules=rules)
        results = processor.process_dataframe(df)

        return results